package hos.thread.executor

import hos.thread.RunnableThis
import hos.thread.ThreadOption

/**
 * <p>Title: TS </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @date : 2023/8/5 12:03
 * @version : 1.0
 */
object TS {

    @JvmStatic
    fun getThread(): ThreadExecutor {
        return ThreadExecutor.thread
    }

    @JvmStatic
    @JvmOverloads
    fun run(
        job: ThreadOption.Job = ThreadOption.Job.ON,
        priority: Int = 0,
        block: ThreadExecutor.() -> Unit,
    ) = ThreadExecutor.run(job, priority, block)

    @JvmStatic
    fun isMainThread(): Boolean {
        return ThreadExecutor.isMainThread()
    }

    /**
     * 运行在工作线程
     *
     * @param runnable 工作线程
     */
    @JvmStatic
    fun postIo(runnable: Runnable): ThreadExecutor {
        return ThreadExecutor.thread.postIo(runnable)
    }

    /**
     * 运行在工作线程
     *
     * @param runnable 工作线程
     */
    @JvmStatic
    @JvmOverloads
    fun postIo(priority: Int = 0, runnable: RunnableThis): ThreadExecutor {
        return ThreadExecutor.thread.postIo(priority, runnable)
    }

    /**
     * 运行在工作线程
     *
     * @param runnable 工作线程
     */
    @JvmStatic
    fun postOnIo(runnable: Runnable): ThreadExecutor {
        return ThreadExecutor.thread.postOnIo(runnable)
    }

    @JvmStatic
    fun remove(runnable: Runnable) {
        ThreadExecutor.thread.remove(runnable)
    }
}